import 'package:flutter/material.dart';

void main() {
  runApp(const MyApp());
}

class MyApp extends StatelessWidget {
  const MyApp({Key? key}) : super(key: key);

  // This widget is the root of your application.
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
        title: 'Flutter Demo',
        theme: ThemeData(
          primarySwatch: Colors.blue,
        ),
        home: Scaffold(
          appBar: AppBar(),
          body: Home(),
        ));
  }
}

class Home extends StatefulWidget {
  const Home({Key? key}) : super(key: key);

  @override
  State<Home> createState() => _HomeState();
}

class _HomeState extends State<Home> {
  int curNum = 0;

  @override
  void initState() {
    // TODO: implement initState
    super.initState();
  }

  add() {
    setState(() {
      curNum += 1;
    });
  }

  minus() {
    setState(() {
      curNum -= 1;
    });
  }

  @override
  Widget build(BuildContext context) {
    return Column(
      children: [
        // Container(
        //   child: FlatButton(
        //     child: Text("+"),
        //     onPressed: () {
        //       add();
        //     },
        //   ),
        // ),
        // Container(
        //   child: Text("$curNum"),
        // ),
        // Container(
        //   child: FlatButton(
        //     child: Text("-"),
        //     onPressed: () {
        //       minus();
        //     },
        //   ),
        // ),
        Add(
          add: add,
        ),
        Container(
          child: Text("$curNum"),
        ),
        Mimus(
          mimus: minus,
        )
      ],
    );
  }
}

class Mimus extends StatelessWidget {
  const Mimus({Key? key, required this.mimus}) : super(key: key);
  final Function mimus;
  @override
  Widget build(BuildContext context) {
    return Container(
      child: FlatButton(
        child: Text("-"),
        onPressed: () {
          mimus();
        },
      ),
    );
  }
}

class Add extends StatelessWidget {
  const Add({Key? key, required this.add}) : super(key: key);

  final Function add;

  @override
  Widget build(BuildContext context) {
    return Container(
      child: FlatButton(
        child: Text("+"),
        onPressed: () {
          add();
        },
      ),
    );
  }
}
